package 题目集.栈;// package acm.pta10;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

//https://pintia.cn/problem-sets/1744287237921226752/exam/problems/1744287275661570056?type=7&page=0
public class 出栈序列的合法性 {

    /**
     * 先看cur能不能直接出，
     * 如果不能，则判断栈里的东西是否可以出来
     * 对下一个cur判断。
     */
    public static boolean isOK(int[] arr, int cap) {
        Stack<Integer> stack = new Stack<>();
        int cur = 1;  //当前入栈的数
        int pos = 0;  //当前出栈的数
        while (cur <= arr.length) {
            if (stack.size() == cap) return false;
            while (!stack.isEmpty() && pos < arr.length && stack.peek() == arr[pos]) {
                stack.pop();
                pos++;
            }
            if (cur == arr[pos]) {
                cur++;
                pos++;
                continue;
            }
            stack.push(cur++);
        }
        //全部入栈完毕，只能出栈了
        while (pos < arr.length) {
            if(stack.pop()!=arr[pos++]){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Reader sc = new Reader();
        int k = sc.nextInt();
        int n = sc.nextInt();
        int m = sc.nextInt();
        while (m-- > 0) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            System.out.println(isOK(arr, k) ? "YES" : "NO");
        }
    }
    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}

